<template>
    <!-- 客户管理模块-客户税收居民身份声明文件编辑页面 -->
    <div class="fillcontain">
        <!-- 标题 -->
        <div class="fastQuery">
            <el-row>
                <el-col :span="6" class="fastQuery_title">
                    <i class="el-icon-tickets"></i><span> 客户税收居民身份声明文件</span></el-col>
                <el-col :span="8"></el-col>
            </el-row>
        </div>
        <div class="contain baseInfo">
            <el-form label-width="120px" class="search_container">
                <el-row class="common-box">
                    <el-col :span="8">
                        <el-col :span="8" class="common-lab">
                            <label class="calname">姓名(投保人)</label>
                        </el-col>
                        <el-col :span="14">
                            <el-input v-model="taxspf.calname"></el-input>
                        </el-col>
                    </el-col>
                </el-row>
                <el-row class="common-box">
                    <el-row>
                        <el-col :span="3" class="common-lab">
                            <label class="pflag pr15">本人声明：</label>
                        </el-col>
                        <el-col :span="21" class="text_left">
                            <el-radio v-model="taxspf.pflag" label="1">1、仅为中国税收居民</el-radio>
                            <el-radio v-model="taxspf.pflag" label="2">2、仅为非居民</el-radio>
                            <el-radio v-model="taxspf.pflag" label="3">3、既是中国税收居民又是其他国家(地区)税收居民</el-radio>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="3">&nbsp;</el-col>
                        <el-col :span="10" style="margin-bottom: 20px;">
                            <label class="tips-txt">如以上选项中勾选2项或第3项，请填写下列信息：</label>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="susrname">姓(英文或拼音)</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.susrname"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="susrgname">名(英文或拼音)</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.susrgname"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="smoddate">出生日期</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.smoddate"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                </el-row>

                <el-row>
                    <el-col :span="24" class="mt10">
                        <div class="title">
                            <span>现居住地(境外地址无需填写中文地址栏)</span>
                        </div>
                    </el-col>
                    <el-col :span="24" class="mt10">
                        <el-col :span="1" class="text_right">中文栏</el-col>
                        <el-col :span="23">
                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="nationdc">国家</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.nationdc"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="sprovname">省</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.sprovname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="scityname">市</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.scityname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="12">
                                <el-col :span="6" class="common-lab">
                                    <label class="lngaddr01">现居详细地址</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.lngaddr01"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-col>

                    <el-col :span="24" class="mt10">
                        <el-col :span="1" class="text_right">英文栏</el-col>
                        <el-col :span="23">
                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="nationabdc">国家</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.nationabdc"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="pprovname">省</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.pprovname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="pcityname">市</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.pcityname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="12">
                                <el-col :span="6" class="common-lab">
                                    <label class="lngaddr02">现居详细地址</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.lngaddr02"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-col>
                </el-row>

                <el-row class="mt20">
                    <el-col :span="24" class="mt10">
                        <div class="title">
                            <span>出生地(境外地址无需填写中文地址栏)</span>
                        </div>
                    </el-col>
                    <el-col :span="24" class="mt10">
                        <el-col :span="1" class="text_right">中文栏</el-col>
                        <el-col :span="23">
                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="cntname">国家</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.cntname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="provname">省</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.provname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="city">市</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.city"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="12">
                                <el-col :span="6" class="common-lab">
                                    <label class="lngaddr03">出生详细地址</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.lngaddr03"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-col>

                    <el-col :span="24" class="mt10">
                        <el-col :span="1" class="text_right">英文栏</el-col>
                        <el-col :span="23">
                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="crname">国家</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.crname"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="prodesc">省</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.prodesc"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="4">
                                <el-col :span="8" class="common-lab">
                                    <label class="citydesc">市</label>
                                </el-col>
                                <el-col :span="16">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.citydesc"></el-input>
                                </el-col>
                            </el-col>

                            <el-col :span="12">
                                <el-col :span="6" class="common-lab">
                                    <label class="lngaddr04">出生详细地址</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input clearable placeholder="" v-model.trim="taxspf.lngaddr04"></el-input>
                                </el-col>
                            </el-col>

                        </el-col>
                    </el-col>
                </el-row>

                <el-row class="mt20">
                    <el-col :span="24" class="mt10">
                        <div class="title">
                            <span>税收居民国(地区)及纳税人居民号</span>
                        </div>
                    </el-col>
                    <el-col :span="24" class="pb10 mt10">
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="sdesc01">税收居民国(地区)1</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.sdesc01"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="pedesc01">纳税人识别号1</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.pedesc01"></el-input>
                            </el-col>
                        </el-col>
                    </el-col>
                    <el-col :span="24" class="pb10">
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="sdesc02">税收居民国(地区)2</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.sdesc02"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="pedesc02">纳税人识别号2</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.pedesc02"></el-input>
                            </el-col>
                        </el-col>
                    </el-col>
                    <el-col :span="24" class="pb10">
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="sdesc03">税收居民国(地区)3</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.sdesc03"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="8" class="common-lab">
                                <label class="pedesc03">纳税人识别号3</label>
                            </el-col>
                            <el-col :span="16">
                                <el-input clearable placeholder="" v-model.trim="taxspf.pedesc03"></el-input>
                            </el-col>
                        </el-col>
                    </el-col>
                </el-row>


                <el-row class="mt20">
                    <el-col :span="24">
                        <span class="pl20 pr20">如不能提供居民国(地区)信息，纳税人识别号，请选择原因</span>
                    </el-col>
                    <el-col :span="24" class="mt10 pl20 pr20">
                        <el-radio v-model="taxspf.reasons" label="1">居民国(地区)不发纳税人识别号</el-radio>
                        <el-radio v-model="taxspf.reasons" label="2">>账户持有人未能取得纳税人识别号，如此选项，请解释具体原因</el-radio>
                    </el-col>
                    <el-col :span="24" class="mt20 pr20 pl20">
                        <el-input clearable type="textarea" v-model.trim="taxspf.pareason"></el-input>
                    </el-col>
                </el-row>

                <el-row class="mt20">
                    <el-col :span="12" class="text_right">
                        <el-button type="danger" class="Defaultbutton" @click="saveTaxspf">保存</el-button>
                    </el-col>
                    <el-col :span="12" class="text_left pl20">
                        <el-button @click="back">返 回</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
</template>
<script>
    import { mapState, mapGetters } from 'vuex'
    import constant from '@/utils/constant';
    import { saveTaxspfInfo, queryIndividualTax } from "@/api/customermanage/customerManage.js";
    export default {
        data() {
            return {
                radio: 3,
                radios: 1,
                clntnum: '',
                taxspf: {
                    "calname": "",
                    "chdrnum": "",
                    "city": "",
                    "citydesc": "",
                    "clntnum": "",
                    "cntname": "",
                    "crname": "",
                    "datime": "",
                    "dtecrt": 0,
                    "job_name": "",
                    "lngaddr01": "",
                    "lngaddr02": "",
                    "lngaddr03": "",
                    "lngaddr04": "",
                    "nationabdc": "",
                    "nationdc": "",
                    "pareason": "",
                    "pcityname": "",
                    "pedesc01": "",
                    "pedesc02": "",
                    "pedesc03": "",
                    "pflag": "",
                    "pprovname": "",
                    "prodesc": "",
                    "provname": "",
                    "reasons": "",
                    "scityname": "",
                    "sdesc01": "",
                    "sdesc02": "",
                    "sdesc03": "",
                    "serno": "",
                    "smoddate": "",
                    "sprovname": "",
                    "susrgname": "",
                    "susrname": "",
                    "userProfile": ""
                },
            }
        }, mounted() { //页面初始化方法
            this.getIndividualTax();
        },
        methods: {
            //个人税收居民身份声明文件
            getIndividualTax() {
                this.$store.dispatch('loading/CHNAGE_SUBLOADING', true)
                this.clntnum = this.$route.query.clntnum;
                let params = {
                    clntnum: this.clntnum
                }
                queryIndividualTax(params).then(res => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                    if (res.resultCode == constant.SUCCESS && res.data) {
                        this.taxspf = res.data;
                        this.trimTaxspf();
                    }
                    this.$emit('checkData', this.tableData.length > 0 ? true : false)
                }).catch(err => {
                    this.$emit('checkData', false)
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                })
            },
            saveTaxspf() {
                this.trimTaxspf();
                if (this.taxspf.reasons) {
                    let reasons_s = this.taxspf.reasons;
                    if (reasons_s == '2' && (this.taxspf.pareason == null || this.taxspf.pareason.length == 0)) {
                        this.popMsg("注意:账户持有人未能取得纳税人识别号，请填写具体原因", "error");
                        return;
                    }
                }
                if (this.taxspf.nationdc || this.taxspf.sprovname || this.taxspf.scityname || this.taxspf.lngaddr01) {
                    if (this.taxspf.nationdc == null || this.taxspf.nationdc.length == 0) {
                        this.popMsg("(中文)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.sprovname == null || this.taxspf.sprovname.length == 0) {
                        this.popMsg("(中文)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.scityname == null || this.taxspf.scityname.length == 0) {
                        this.popMsg("(中文)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.lngaddr01 == null || this.taxspf.lngaddr01.length == 0) {
                        this.popMsg("(中文)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                }
                if (this.taxspf.nationabdc || this.taxspf.pprovname || this.taxspf.pcityname || this.taxspf.lngaddr02) {
                    if (this.taxspf.nationabdc == null || this.taxspf.nationabdc.length == 0) {
                        this.popMsg("(英文或拼音)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.pprovname == null || this.taxspf.pprovname.length == 0) {
                        this.popMsg("(英文或拼音)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.pcityname == null || this.taxspf.pcityname.length == 0) {
                        this.popMsg("(英文或拼音)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.lngaddr02 == null || this.taxspf.lngaddr02.length == 0) {
                        this.popMsg("(英文或拼音)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                }
                if (this.taxspf.cntname || this.taxspf.provname || this.taxspf.city || this.taxspf.lngaddr03) {
                    if (this.taxspf.cntname == null || this.taxspf.cntname.length == 0) {
                        this.popMsg("(中文)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.provname == null || this.taxspf.provname.length == 0) {
                        this.popMsg("(中文)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.city == null || this.taxspf.city.length == 0) {
                        this.popMsg("(中文)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.lngaddr03 == null || this.taxspf.lngaddr03.length == 0) {
                        this.popMsg("(中文)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                }
                if (this.taxspf.crname || this.taxspf.prodesc || this.taxspf.citydesc || this.taxspf.lngaddr04) {
                    if (this.taxspf.crname == null || this.taxspf.crname.length == 0) {
                        this.popMsg("(英文或拼音)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.prodesc == null || this.taxspf.prodesc.length == 0) {
                        this.popMsg("(英文或拼音)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.citydesc == null || this.taxspf.citydesc.length == 0) {
                        this.popMsg("(英文或拼音)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                    if (this.taxspf.lngaddr04 == null || this.taxspf.lngaddr04.length == 0) {
                        this.popMsg("(英文或拼音)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空", "error");
                        return;
                    }
                }
                this.taxspf.clntnum = this.clntnum
                this.$store.dispatch('loading/CHNAGE_SUBLOADING', true)
                saveTaxspfInfo(this.taxspf).then(res => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                    if (res.resultCode == constant.SUCCESS && res.data) {
                        alert("保存成功");
                        this.$router.go(-1);//返回上一层
                    }
                }).catch(err => {
                    alert("保存失败");
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                })

            },
            trimTaxspf() {
                this.trim(this.taxspf.calname);
                this.trim(this.taxspf.chdrnum);
                this.trim(this.taxspf.city);
                this.trim(this.taxspf.citydesc);
                this.trim(this.taxspf.clntnum);
                this.trim(this.taxspf.cntname);
                this.trim(this.taxspf.crname);
                this.trim(this.taxspf.datime);
                this.trim(this.taxspf.job_name);
                this.trim(this.taxspf.lngaddr01);
                this.trim(this.taxspf.lngaddr02);
                this.trim(this.taxspf.lngaddr03);
                this.trim(this.taxspf.lngaddr04);
                this.trim(this.taxspf.nationabdc);
                this.trim(this.taxspf.nationdc);
                this.trim(this.taxspf.pareason);
                this.trim(this.taxspf.pcityname);
                this.trim(this.taxspf.pedesc01);
                this.trim(this.taxspf.pedesc02);
                this.trim(this.taxspf.pedesc03);
                this.trim(this.taxspf.pflag);
                this.trim(this.taxspf.pprovname);
                this.trim(this.taxspf.prodesc);
                this.trim(this.taxspf.provname);
                this.trim(this.taxspf.reasons);
                this.trim(this.taxspf.scityname);
                this.trim(this.taxspf.sdesc01);
                this.trim(this.taxspf.sdesc02);
                this.trim(this.taxspf.sdesc03);
                this.trim(this.taxspf.serno);
                this.trim(this.taxspf.smoddate);
                this.trim(this.taxspf.sprovname);
                this.trim(this.taxspf.susrgname);
                this.trim(this.taxspf.susrname);
                this.trim(this.taxspf.userProfile);
                console.log(this.taxspf);
            },
            trim(val) {
                if (val == undefined) {
                    return '';
                }
                return val.replace(/(^\s*)|(\s*$)/g, '')
            },
            popMsg(message, type) {
                this.$message({
                    message: message,
                    type: type
                });
            },
            back() {
                this.$router.go(-1);//返回上一层
            },
        },
        watch: {
            "$route": {
                handler(route) {
                    if (route.query.clntnum != undefined && route.query.clntnum != this.clntnum) {
                        this.getIndividualTax();
                    }
                }
            }
        }
    }

</script>

<style lang="less" scoped>
    .fillcontain {
        padding-bottom: 0;

        .fastQuery {
            padding: 15px 20px 10px 20px;
            background: #fff;
            border-bottom: 1px solid #e1e1e1;

            .fastQuery_title {
                color: #666;
                padding: 6px 0px;
            }
        }
    }

    .contain {
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }

    .common-box {
        padding-bottom: 15px;
    }

    .tips-txt {
        color: #F76565;
    }

    .common-lab {
        line-height: normal!important;
        text-align: right;
        .labelName {
            text-align: right;
        }
    }
</style>